package com.grademaster.controller;

import com.grademaster.common.R;
import com.grademaster.dto.GradePageDto;
import com.grademaster.entity.Grades;
import com.grademaster.service.GradesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/grades")
@Api(tags = "年级相关接口")
@CrossOrigin(origins = {"http://localhost:8081"}, allowCredentials = "true")
public class GradesController {

    @Autowired
    private GradesService gradesService;

    @ApiOperation("获取所有年级信息")
    @GetMapping("/getAllGrades")
    public R getAllGrades() {
        return gradesService.getAllGrades();
    }

    @ApiOperation("获取所有年级分页信息")
    @GetMapping("/getAllGradesByPage")
    public R getAllGradesByPage(GradePageDto gradePageDto) {
        return gradesService.getAllGradesByPage(gradePageDto);
    }
    @ApiOperation("导出成绩列表到Excel")
    @GetMapping("/exportExcel")
    public ResponseEntity exportExcel(GradePageDto gradePageDto){
        return gradesService.exportExcel(gradePageDto);
    }

    @ApiOperation("添加或修改年级信息")
    @PostMapping("/addOrEditGrade")
    public R addOrEditGrade(@RequestBody Grades grades) {
        return gradesService.addOrEditCollege(grades);
    }

    @ApiOperation("删除年级")
    @DeleteMapping("/deleteGrade/{gradeId}")
    public R deleteGrade(@PathVariable("gradeId") String gradeId) {
        return gradesService.deleteGrade(gradeId);
    }
}
